import Vue from 'vue'
import VueRouter from 'vue-router'
import Component from './page';
import store from '@/store/index.js';
/*
import IndexPage from '@/views/indexPage/indexPage.vue'
// import Board from '../views/indexPage/board/board.vue'
import Board from '../views/indexPage/board/board_1.vue'
import User from '../views/indexPage/user/user.vue'

import Operation from '../views/indexPage/logs/operation.vue'
import Logon from '../views/indexPage/logs/logon.vue'
import { resolve } from 'core-js/fn/promise' */
/* import Tabs from '@/components/indexPageTabs/Tabs.vue' */


//处理路由重复跳转报错
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
    //push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
        if (onResolve || onReject) return originalPush.call(this, location,

            onResolve, onReject)
        return originalPush.call(this, location).catch(err => err)
    }
    //replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalReplace.call(this, location,

        onResolve, onReject)
    return originalReplace.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/indexPage'
    }, {
        path: '/indexPage',
        name: 'indexpage',
        component: Component.IndexPage,
        meta: {
            title: '首页'
        },
    },
    {
        path: '/auth',
        name: 'auth',
        component: Component.Auth,
        meta: {
            title: '权限配置'
        },
    },
    {
        path: '/login',
        name: 'login',
        meta: {
            title: '登录'
        },
        component: Component.Login,
    },
    {
        path: '/board',
        name: 'board',
        meta: {
            keepAlive: true,
            isShow: false,
            title: '运营看板'
        },
        component: Component.Board,
    },
    {
        path: '/logs',
        name: 'user',
        meta: {
            /* isShow: false, */
            name: '个人中心',
            title: '个人中心'
        },
        redirect: '/logs/logon',
        component: Component.User,
        children: [{
                path: '/logs/logon',
                meta: {
                    name: '我的信息',
                    keepAlive: true,
                    isShow: true,
                    title:

                        '个人中心/我的信息'
                },
                component: Component.Logon,

            },
            {
                path: '/logs/operation',
                meta: {
                    name: '任务明细',
                    keepAlive: true,
                    isShow: true,
                    title:

                        '个人中心/任务明细'
                },
                component: Component.Operation,

            }
        ]
    },

]



const router = new VueRouter({
    mode: 'hash',
    routes
})
router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title
        if (to.path === '/auth') {
            console.log(localStorage.getItem('authIsLogin'));
            if (localStorage.getItem('authIsLogin')) {
                next()
            } else {
                next({ name: 'login' })
            }
        } else {
            next()
        }
    }


})
export {
    routes
}
export default router